<template>
  <div class="c-bg-sgray">
    <cust-index-com
      :pageName="'MICRO_PAGE'"
      :isHomePage='true'
      :isShowMemberTips="isShowMemberTips"
      :memberTips="memberTips"
      :dataList="dataList"
      :upgradeMemberJump='upgradeMemberJump'
    ></cust-index-com>
  </div>
</template>
<script>
import custIndexCom from '@/components/templates/custIndexCom.vue';
import { utilJs } from "@/utils/common.js";
import { appRouterChange } from "@/mixin/appRouterPush.js";
export default {
  mixins: [appRouterChange],
  components: {
    custIndexCom,
  },
  props: {
    tName: {
      type: String,
      default: "mb7"
    }
  },
  data() {
    return {
      getCouponCount: "",
      getAlready: false,
      companyAuth: JSON.parse(localStorage.getItem("companyAuth")),
      theme: "mb7_blue",
      isShowMemberTips: false, // 是否显示续费
      memberTips: "您的会员即将到期，请续费~", // 会员提示语
      showExpire: false, // 时间是否到期
      isiOS: navigator.userAgent.indexOf('IOSLogin') > -1 || navigator.userAgent.indexOf('IOSNewLogin') > -1 || navigator.userAgent.indexOf("IOSNewApp") > -1,
      dataList: [],
      upgradeMemberJump: '',
      mId: localStorage.getItem("mId"),
    };
  },
  created() {
  },
  mounted() {
    this.companyAuth = JSON.parse(localStorage.getItem("companyAuth"));
    let expireTime = new Date().getTime() + 1000 * 60;
    // 解决有时候白屏问题
    if (this.companyAuth) {
        expireTime = utilJs.getTimeByDate(this.companyAuth.expireTime);
    }
    // 判断体验版是否到期，到期之后不可购买商品
    this.showExpire = expireTime - (new Date()).getTime() < 0
    if (!this.showExpire) {
      //this.dataList = [];
      this.getIndexInfo();
    } else {
      let isExireTime = new Date().getTime() - expireTime > 7776000000; // 过期时间超过3个月
      this.$cjConfirm({
        title: '店铺已打烊',
        message: `打烊期间无法购买商品，${isExireTime ? '无法访问!' : '所有服务停止!'}`,
        showCancelButton: false,
        clickCloseModal: false,
        onConfirm:() => {
          this.getIndexInfo();
        }
      })
    }
  },
  computed: {},
  watch: {
    $route(to, from) {
      if (to.path == "/") {
        //this.dataList = [];
        this.getIndexInfo();
      }
    }
  },
  methods: {
    //获取首页相关数据
    getIndexInfo() {
      this.$loading.show();
      let that = this;
      let tempUrl = this.tName == 'mb7' ? ((this.mId == null || this.mId == 0) ? "company/customTemplates" : "company/customTemplates?id=" + this.mId) : "company/customTemplates?themeName=mb8";
      if (this.$isWxApp()) {
        tempUrl = `${tempUrl}${this.tName == 'mb7' && (this.mId == null || this.mId == 0) ? '?' : '&'}isMiniHomePage=1`
      }
      utilJs.getMethod(global.apiurl + tempUrl, function (res) {
        that.$loading.hide();
        that.companyAuth = JSON.parse(localStorage.getItem("companyAuth"));
        that.$store.commit('updateUserVipType', res.userType);
        localStorage.setItem(
          "vipType" + localStorage.getItem("userId"),
          res.userType
        );
        if (
          (res.userType == 2 || res.userType == 4) &&
          res.vipDay <= 7 &&
          res.vipDay >= 0
        ) {
          let userTypeName = res.userType == 2 ? 'VIP' : 'SVIP';
          if (Number(res.vipDay) == 0) {
            that.memberTips =
            "您的" + userTypeName + "会员今天过期，";
          } else {
            that.memberTips =
            "您的" + userTypeName + "会员还有" + res.vipDay + "天过期，";
          }
          that.isShowMemberTips = true;
        } else {
          that.isShowMemberTips = false;
        }

        that.dataList = res.modules;
        that.upgradeMemberJump = res.upgradeMemberJump + '';
        that.theme = res.color ? res.color : 'mb7_blue';
        let title = window.localStorage.getItem("shareTitle") || window.localStorage.getItem("companyName");
        let shareImg = window.localStorage.getItem("shareLogo");
        let shareDesc = window.localStorage.getItem("shareDesc");
        let shareUrl =
          window.location.href.split("#")[0] +
          "#" +
          that.$route.path +
          "?refereeId=" +
          localStorage.getItem("userId");
        utilJs.wechatConfig(
          shareUrl,
          title,
          shareImg,
          shareDesc,
          function () { }
        );
      }, failRes => {
        that.$loading.hide();
      });
    },
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>
